package com.cfweb.util;

import java.net.URI;
import java.util.Enumeration;

import javax.servlet.http.HttpSession;

import com.cfweb.api.OauthApi;

public class CfSession {
	@SuppressWarnings("rawtypes")
	public static HttpSession getSession(HttpSession session) throws Exception {
		session.setAttribute("username", "admin");
		session.setAttribute("userIsAdmin", "1");
		session.setAttribute("target", URI.create("http://api.yjs.cf").toURL());
		session.setAttribute("space", "space22");
		session.setAttribute("org", "org2");
		session.setAttribute("userid", "9724436f-5faf-4ac4-a65c-d848c9044c0a");
		session.setAttribute("user_primaryid", "1");
		session.setAttribute("token", OauthApi.login("admin", "admin", session));

		Enumeration e = session.getAttributeNames();
		System.out.println("----下面循环输出Session所有属性及其值：");
		for (; e.hasMoreElements();) {
			String temp = (String) e.nextElement();
			System.out.print(temp + " = ");
			System.out.println(session.getAttribute(temp));
		}
		// System.out.println("++++++++++++++");
		// OauthToken token123 = (OauthToken) session.getAttribute("token");
		// System.out.println(token123.getAccessToken());
		// System.out.println(token123.getTokenType());
		// System.out.println(token123.getRefreshToken());
		// System.out.println(token123.getExpirationIn());
		// System.out.println("++++++++++++++");
		return session;
	}
}
